package liu.per.dict;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by liuj on 2015/4/19.
 */
public class DictTree {

    private String origin;
    private int freq = 1;
    private char value;
    //26
    private DictTree[] children = new DictTree[26];
    private Set<Integer> nodeSet = new HashSet<>();

    public DictTree() {
    }

    public void add(DictTree root, String str) {

        int i = str.charAt(0) - 'a';
        DictTree next = root.getChildren()[i];
        root.getNodeSet().add(i);
        if (next == null) {
            next = new DictTree();
            next.value = str.charAt(0);
            root.getChildren()[i] = next;
        } else {
            root.getChildren()[i].freq++;
        }
        if (str.length() > 1) {
            add(next, str.substring(1));
        }
    }

    public char getValue() {
        return value;
    }

    public void setValue(char value) {
        this.value = value;
    }

    public String getOrigin() {
        return origin;
    }

    public void setOrigin(String origin) {
        this.origin = origin;
    }

    public DictTree[] getChildren() {
        return children;
    }

    public void setChildren(DictTree[] children) {
        this.children = children;
    }

    public int getFreq() {
        return freq;
    }

    public void setFreq(int freq) {
        this.freq = freq;
    }

    public Set<Integer> getNodeSet() {
        return nodeSet;
    }

    public void setNodeSet(Set<Integer> nodeSet) {
        this.nodeSet = nodeSet;
    }
}
